﻿var imageUpload = (function () {

    function Singleton(args) {

        //设置args变量为接收的参数或者为空（如果没有提供的话）
        var args = args || {};
        return {
            upload_url: args.uploadUrl,
            button_placeholder_id: args.placeHoldId,
            flash_url: "/JS/swfUploadImg/Flash/swfupload.swf",
            file_size_limit: args.sizeLimit || "5 MB",
            file_types: args.fileType || "*.*",
            file_types_description: "All Files",
            file_upload_limit: 100,
            file_queue_limit: 3,

            button_image_url: "/JS/swfUploadImg/XPButtonUploadText_61x22.png" || args.button_image_url,
            button_width: args.width || "60",
            button_height: args.height || "20",
            queueContainId: args.queueContainId || "",
            removeClass: args.removeClass || "",
            moving_average_history_size: 40,

            file_queued_handler: args.fileQueued || $.syhupload.fileQueued,
            file_queue_error_handler: args.fileQueueError || $.syhupload.fileQueueError,
            file_dialog_complete_handler: args.fileDialogComplete || $.syhupload.fileDialogComplete,
            upload_start_handler: args.uploadStart || $.syhupload.uploadStart,
            upload_progress_handler: args.uploadProgress || $.syhupload.uploadProgress,
            upload_success_handler: args.uploadSuccess || $.syhupload.uploadSuccess,
            upload_complete_handler: args.uploadComplete || $.syhupload.uploadComplete
        };


    };
    

    //实例容器
    var swfu;
    var _static = {

        //获取实例的方法
        //返回Singleton的实例
        getInstance: function (args) {
            if (swfu === undefined) {
                swfu = new SWFUpload(new Singleton(args));
            }
            return swfu;
        },
 

        startUpload: function (file) {
            if (swfu.getStats().files_queued > 0) {
                swfu.startUpload(file);
            }
        }
    };
    return _static;
})();